#include <cacheflex.h>
#include <framework.h>

void *STORE_LIBC_get_interface(generic_alloc_pt alloc, generic_free_pt free)
{
    store_interface_t *ret = NULL;
    if (!(ret = alloc(sizeof(store_interface_t))))
        return NULL;

    memset(ret, 0, sizeof(store_interface_t));

    ret->alloc          =   libc_alloc;
    ret->free           =   libc_free;
    ret->ref_buffer     =   libc_ref_buffer;
    ret->deref_buffer   =   libc_deref_buffer;

    return ret;
}
static int libc_alloc(cacheflex_t *cache, const int64_t nbytes, store_handle_t *sh)
{
    void *ret = NULL;
    if (ret = malloc(nbytes))
    {
        *sh = (store_handle_t)ret;
        return 0;
    }
    else
    {
        *sh = CF_NULL_STORE_HANDLE;
        return 1;
    }
}

static void *libc_ref_buffer(cacheflex_t *cache, const store_handle_t sh)
{
	return (void *)sh;
}

static void deref_buffer(cacheflex_t *cache, const store_handle_t sh, const int dirty)
{
	(void)dirty;

}
